package com.cci.kangdao.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.service.NotifyRecordTService;
import com.cci.kangdao.utilTool.AESTool;
import com.cci.kangdao.utilTool.ParameterTool;
/**
 * 服务车类controller
 *
 */
@Controller
public class NotifyRecordTController {
	
	private Logger log = Logger.getLogger(this.getClass().getName());
	
	@Autowired
	private NotifyRecordTService notifyRecordTService;
	
	
	/**
	 * 根据用户id和Category获取消息推送集合
	 * @param map
	 * @return
	 */
	@RequestMapping("/getNotifyRecordTListByUserIdCategory.aspx")
	public ModelAndView getNotifyRecordTListByUserIdCategory(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return notifyRecordTService.getNotifyRecordTListByUserIdCategory(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 *登录人点击消息后，把消息是否已读状态改为已读
	 * @param map
	 * @return
	 */
	@RequestMapping("/updateNotifyRecordTById.aspx")
	public ModelAndView updateNotifyRecordTById(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return notifyRecordTService.updateNotifyRecordTById(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}

	/**
	 * 获取工单消息列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/getWorkOrderNotifyRecordList.aspx")
	public String getWorkOrderNotifyRecordList(HttpServletRequest request,HttpServletResponse response){
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			notifyRecordTService.getWorkOrderNotifyRecordList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
		return null;
	}

	@RequestMapping(value = "/updateNotifyReadStatusByCategory.aspx",method = RequestMethod.POST)
	public void updateNotifyRecordByCategory(HttpServletRequest request,HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			notifyRecordTService.updateNotifyReadStatusByCategory(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}


}
